﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MsDAL;
using Components;
using System.Collections;
using Model;

namespace ServiceHelper
{
    public class Sys5a01Manager
    {
        Sys5a01DAL dal = new Sys5a01DAL();

        private static Sys5a01Manager _entity;
        /// <summary>
        /// 得到PersonManager类的实体对象
        /// </summary>
        public static Sys5a01Manager Entity
        {
            get
            {
                if (_entity == null)
                    _entity = new Sys5a01Manager();
                return _entity;
            }
        }

        /// <summary>
        /// 根据页面和控件得到字段列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="ctl"></param>
        /// <returns></returns>
        public DataTable GetList(string page, string ctl)
        {
            return dal.GetList(page, ctl);
        }

        public string SaveData(Hashtable tb, DataTable dtl, DataTable deldata, string action, string usercode)
        {
            List<SqlApp> lst = new List<SqlApp>();

            if ("M" == action) //修改宽度
            {
                int width = 0;
                string listid = string.Empty;
                StringBuilder sb = new StringBuilder();
                foreach (DataRow dr in dtl.Rows)
                {
                    listid = Components.Validation.ToString(dr["listid"]);
                    width = Components.Validation.ToInt(dr["columnwidth"]);

                    lst.Add(dal.UpdateWidth(listid, width));

                    sb.AppendFormat(template, width, listid);
                    sb.AppendLine();
                }

                CommonUtil.GetInstance.SaveToFile("D:\\upWidth.sql", sb.ToString());
            }

            return CommonManager.Entity.SaveData(lst);
        }

        /// <summary>
        /// 记录更新宽度脚本
        /// </summary>
        private string template = "UPDATE Sys5a01 SET columnwidth = '{0}' WHERE listid ='{1}'; ";
    }
}
